import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);
let routeArr = [{
		name: 'home',
		path: 'home/index',
		meta: {
			title: '首页',
			noBack: true,
			showF: true
		}
	},
	{
		name: 'newsDetail',
		path: 'home/detail',
		meta: {
			title: '详情'
		}
	},
	{
		name: 'application',
		path: 'application/index',
		meta: {
			title: '应用',
			noBack: true,
			showF: true
		}
	},
	{
		name: 'kaohe',
		path: 'application/kaohe',
		meta: {
			title: '年度考核',
			noBack: false
		}
	},
	{
		name: 'qiandao',
		path: 'application/qiandao',
		meta: {
			title: '签到',
			noBack: false
		}
	},

	{
		name: 'self',
		path: 'self/index',
		meta: {
			title: '个人中心',
			noBack: true,
			showF: true
		}
	},
	{
		name: 'about',
		path: 'self/about',
		meta: {
			title: '关于',
			showF: true
		}
	},

	{
		name: 'login',
		path: 'login/login',
		meta: {
			title: '登录',
			noBack: true
		}
	},
]

const routes = [];
routeArr.forEach((val, index, arr) => {
	//判断meta中是否存在showH属性
	if(!val.meta.hasOwnProperty("showH")) {
		val.meta.showH = true
	}
	let route = {
		path: val.name == 'home' ? '/' : '/' +
			val.name, //网站默认页
		name: val.name,
		component: () =>
			import('@/pages/' + val.path),
		meta: val.meta
	};
	routes.push(route)
});
const router = new Router({
	routes: routes
});
router.beforeEach((to, from, next) => {
	document.title = to.meta.title;
	if(to.name == 'login' || localStorage.getItem('token') || sessionStorage.getItem('token')) {
		next();
	} else {
		next('/login');
	}

});
export default router